package com.example.generate.factory;

import com.example.generate.dao.GeneratorDao;
import com.example.generate.dao.MySQLGeneratorDao;
import com.example.generate.dao.OracleGeneratorDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;

/**
 * @author chenjf
 * @Date 2022/9/19
 * @Description 生成产品工厂
 */
@Configuration
public class GeneratorFactory {

    @Value("${generate.datasource}")
    private String datasource;

    @Autowired
    private MySQLGeneratorDao mysqlGeneratorDao;
    @Autowired
    private OracleGeneratorDao oracleGeneratorDao;

    @Bean
    @Primary
    public GeneratorDao getGeneratorDao() {
        if ("mysql".equalsIgnoreCase(datasource)) {
            return  mysqlGeneratorDao;
        } else if ("oracle".equalsIgnoreCase(datasource)) {
            return  oracleGeneratorDao;
        } else {
            throw new RuntimeException("暂未适配" + datasource + "数据库");
        }
    }

}
